const int PANELS = 10;
const int P_SUB1 = 9;
const int P_SUB2 = 8;



__kernel void
solve_force_x4(
constant        float4  *   cell_coord,   //x,y,z,size
constant        int     *   cell_next,
global  const   float   *   pressure,
global          float4  *   force_acc
) {
    int i = get_global_id(0);
    int tmpi = i*6;
    private int n[6];
    //
    n[0] = cell[tmpi++];
    n[1] = cell[tmpi++];
    n[2] = cell[tmpi++];
    n[3] = cell[tmpi++];
    n[4] = cell[tmpi++];
    n[5] = cell[tmpi];
    //
}





int getIndex(int _p, int _u, int _v, int sideLength) 
{
    int p = _p;
    int u = _u;
    int v = _v;
    while (u < 0 || u >= sideLength || v < 0 || v >= sideLength) {
        if ((p & 1) == 0) {
            if (u == 0 && v == sideLength) {
                return PANELS * sideLength * sideLength;
            }
            if (u < 0) {
                int tmp = v;
                v = sideLength + u;
                u = tmp;
                p = (p + P_SUB2) % PANELS;
                } else if (u >= sideLength) {
                u -= sideLength;
                p = (p + 1) % PANELS;
                } else if (v < 0) {
                v += PANELS;
                p = (p + P_SUB1) % PANELS;
                } else if (v >= sideLength) {
                int tmp = u;
                u = v - sideLength;
                v = sideLength - tmp;
                p = (p + 2) % PANELS;
            }
            } else {
            if (v == 0 && u == sideLength) {
                return PANELS * sideLength * sideLength + 1;
            }
            if (u < 0) {
                u += sideLength;
                p = (p + P_SUB1) % PANELS;
                } else if (u >= sideLength) {
                int tmp = v;
                v = u - sideLength;
                u = sideLength - tmp;
                p = (p + 2) % PANELS;
                } else if (v < 0) {
                int tmp = u;
                u = v + sideLength;
                v = sideLength - tmp;
                p = (p + P_SUB2) % PANELS;
                } else if (v >= sideLength) {
                v -= sideLength;
                p = (p + 1) % PANELS;
            }
        }
    }
    return u + sideLength * (v + sideLength * p);
}